
import ViewBase from "../../engine/ViewBase";
import { UserModel } from "../model/UserModel";
import { UIHelper } from "../util/UIHelper";

const { ccclass, property } = cc._decorator;

@ccclass
export default class ViewGameRecordFilter extends ViewBase {

    private txtSearchId: cc.Label;
    private searchCallback: Function;

    public onInitChild(searchCallback: Function) {
        this.searchCallback = searchCallback;
    }

    onEnable(): void {
        super.onEnable();
        this.txtSearchId = this.getChild(this.node, "txtSearchId", cc.EditBox)

        let btnSearch: cc.Node = this.findChild(this.node, "btnSearch")
        UIHelper.onAddEvent(btnSearch, () => {
            if(this.txtSearchId.string == ""){
                UIHelper.showTip("请输入id")
                return;
            }
            this.closeView()
            this.searchCallback(parseInt(this.txtSearchId.string))
        })

        let btnLookMe: cc.Node = this.findChild(this.node, "btnLookMe")
        UIHelper.onAddEvent(btnLookMe, () => {
            this.closeView()
            this.searchCallback(UserModel.instance.userId)
        })

        let btnLookAll: cc.Node = this.findChild(this.node, "btnLookAll")
        UIHelper.onAddEvent(btnLookAll, () => {
            this.closeView()
            this.searchCallback(0)
        })

    }

}
